package com.example.jin.myapplication;


import android.app.Activity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.support.v7.app.AppCompatActivity;

/**
 * Created by jin on 2016/5/30.
 */
public abstract class SingleFragmentActivity extends AppCompatActivity{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(getLayout());

        FragmentManager manager=getSupportFragmentManager();
        Fragment fragment=manager.findFragmentById(R.id.framelayout);
        if(fragment==null){
            fragment=createFragment();
            manager.beginTransaction()
                    .add(R.id.framelayout,fragment)
                    .commit();
        }
    }
    protected abstract Fragment createFragment();
    protected int getLayout(){
        return R.layout.activity_main;
    }
}
